var YY = {};
YY.post = function (obj) {
    if(!obj || !obj.url || !obj.sign || !obj.param){
        return;
    }

    $.ajax({
        url: obj.url,
        type: 'POST',
        dataType:'json',
        data:JSON.stringify(obj.param),
        beforeSend: function (xhr) {
            YY.xhrHandle(xhr,obj);
        },
        async: false,
        cache: false,
        contentType: 'application/json;charset=UTF-8',
        success: function(res){
            obj.okCallback ? obj.okCallback.call(null, res) : function(){}
        },
        error:function(ret){
            obj.errorCallback ? obj.errorCallback.call(null, ret) : function(){}
        }
    });
};

YY.xhrHandle = function(xhrObj,paramObj){
    xhrObj.setRequestHeader("ts", paramObj.time);
    xhrObj.setRequestHeader("mn", "3");
    xhrObj.setRequestHeader("chid", "0");
    xhrObj.setRequestHeader("version","1.0");
    if(paramObj.token){
        xhrObj.setRequestHeader("token",paramObj.token);
    }
    xhrObj.setRequestHeader("sign", paramObj.sign);
}


